// tcp 服务端
const { log } = require('console')
const net = require('net')

const serve = net.createServer()

serve.on('connection',function (clientSocket) {
    console.log('有新的的连接进来了');

    clientSocket.write('hello')

    clientSocket.setKeepAlive(true)

    // 接受客户端信息
    clientSocket.on('data',data=>{
        console.log('客户端说',data.toString());
    })

    clientSocket.on('end',()=>{
        console.log('客户端关闭了');
        // serve.close()
    })

})

serve.on('close',()=>{
    console.log('关闭连接时触发');
})

serve.listen(3000,()=>{
    console.log('服务器启动');
})